package com.yx.system.dao;

import com.baomidou.mybatisplus.plugins.Page;
import com.yx.system.dto.BookStatisticsDto;
import com.yx.system.entity.TdBook;
import com.yx.system.entity.TdOrder;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

/**
 * 订单
 */
@Mapper
@Repository
public interface TdOrderMapper {

    int deleteByPrimaryKey(Integer id);

    int insert(TdOrder record);

    int insertSelective(TdOrder record);

    TdOrder selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TdOrder record);

    int updateByPrimaryKey(TdOrder record);

    /**
     * 查询书籍列表
     */
    List<TdOrder> queryList(Map<String, Object> map);

    /**
     * 查询总数
     */
    int queryTotal(Map<String, Object> map);

    List<TdOrder> queryAll();

    TdOrder queryByBillNo(String billNo);

    List<TdOrder> queryPageList(Page<TdOrder> page, Map<String, Object> map);

    /**
     * 查询当月所有书籍销售总额
     * @param pageUtil
     * @param map
     * @return
     * sql select o.bookid,b.bookName,sum(o.totalFee),b.source from td_order o inner join td_book b on o.bookid = b.id where DATE_FORMAT(o.createDate,'%Y-%m')=DATE_FORMAT(now(),'%Y-%m') and o.orderStatus='success' GROUP BY o.bookid
     */
    List<BookStatisticsDto> sameMonth(Page<BookStatisticsDto> pageUtil, Map<String, Object> map);

    /**
     * 查询录入月份所有书籍销售总额
     * @param pageUtil
     * @param map
     * @return
     * sql select o.bookid,b.bookName,sum(o.totalFee),b.source from td_order o inner join td_book b on o.bookid = b.id where DATE_FORMAT(o.createDate,'%Y-%m')=DATE_FORMAT(now(),'%Y-%m') and o.orderStatus='success' GROUP BY o.bookid
     */
    List<BookStatisticsDto> sameMonth2(Page<BookStatisticsDto> pageUtil, Map<String, Object> map);


    /**
     * 查询所有书籍所有销售总额
     * @param pageUtil
     * @param map
     * @return
     * sql  select o.bookid,b.bookName,sum(o.totalFee),b.source from td_order o inner join td_book b on o.bookid = b.id where o.orderStatus='success' GROUP BY o.bookid
     */
    List<BookStatisticsDto> allStatistics(Page<BookStatisticsDto> pageUtil, Map<String, Object> map);

    /*
    * 查询日/月/年订阅总和
    */
    Integer orderByCondition(Map<String,Object> map);

    List<TdOrder> findByDate(Map<String, Object> map);

    Integer findSubscibeSumByCid(Integer id);

    Integer findRechargeSumByCid(Integer id);

    List<TdOrder> findSubscibeByCid(Integer id);

    List<TdOrder> findRechargeByCid(Integer id);
}